<template>
  <div class="authority">
    <div class="left">
      <div class="title1">
        <h4>
          <el-icon><Setting /></el-icon>&nbsp;角色列表
        </h4>
      </div>
      <el-tree
        :data="data"
        :props="defaultProps"
        accordion
        @node-click="handleNodeClick"
      />
    </div>
    <div class="right">
      <div class="title2">角色权限分配</div>
      <div class="custom-tree-node-container">
        <div class="tree" v-if="show1">
          <el-tree
            :data="data1"
            show-checkbox
            node-key="id"
            default-expand-all
            :expand-on-click-node="false"
            :props="{ class: customNodeClass }"
            :render-content="renderContent"
          />
        </div>
        <div class="tree" v-else>
          <el-tree
            :data="data2"
            show-checkbox
            node-key="id"
            default-expand-all
            :expand-on-click-node="false"
            :props="{ class: customNodeClass }"
            :render-content="renderContent"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import {ref} from 'vue'
import { Setting } from "@element-plus/icons-vue";
let show1 = ref(true);
// let show2 = false;
const data = [
  {
    label: "测试管理员",
    children: [
      {
        label: "三级角色测试",
      },
    ],
  },
];

const data1 = [
  {
    id: 1,
    label: "商品信息",
    children: [
      {
        id: 1,
        label: "商品分类",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "导入",
            className: "leap",
          },
          {
            id: 6,
            label: "导出",
            className: "leap",
          },
          {
            id: 7,
            label: "测试按钮",
            className: "leap",
          },
        ],
      },
      {
        id: 2,
        label: "商品信息",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "审核",
            className: "leap",
          },
        ],
      },
      {
        id: 3,
        label: "商品信息tree",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
        ],
      },
    ],
  },
  {
    id: 1,
    label: "订单管理",
    children: [
      {
        id: 1,
        label: "订单管理",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "导出",
            className: "leap",
          },
          {
            id: 6,
            label: "打印",
            className: "leap",
          },
        ],
      },
      {
        id: 2,
        label: "新订单",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "删除",
            className: "leap",
          },
          {
            id: 3,
            label: "编辑",
            className: "leap",
          },
          {
            id: 4,
            label: "导出",
            className: "leap",
          },
        ],
      },
      {
        id: 3,
        label: "采购订单",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "删除",
            className: "leap",
          },
        ],
      },
      {
        id: 4,
        label: "退货订单",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "导出",
            className: "leap",
          },
        ],
      },
      {
        id: 5,
        label: "订单详情",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "导出",
            className: "leap",
          },
        ],
      },
    ],
  },
  {
    id: 1,
    label: "订单管理",
    children: [
      {
        id: 1,
        label: "订单管理",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "导出",
            className: "leap",
          },
          {
            id: 6,
            label: "打印",
            className: "leap",
          },
        ],
      },
      {
        id: 2,
        label: "新订单",
        isPenultimate: true,
        children: [
        {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "导入",
            className: "leap",
          },
          {
            id: 6,
            label: "导出",
            className: "leap",
          },
        ],
      },
      {
        id: 2,
        label: "省市县",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "导出",
            className: "leap",
          },
        ],
      },

    ],
  },
];
const data2 = [
  {
    id: 1,
    label: "商品信息",
    children: [
      {
        id: 1,
        label: "商品分类",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "导入",
            className: "leap",
          },
          {
            id: 6,
            label: "导出",
            className: "leap",
          },
          {
            id: 7,
            label: "测试按钮",
            className: "leap",
          },
        ],
      },
      {
        id: 2,
        label: "商品信息",
        isPenultimate: true,
        children: [
          {
            id: 1,
            label: "查询",
            className: "leap",
          },
          {
            id: 2,
            label: "新建",
            className: "leap",
          },
          {
            id: 3,
            label: "删除",
            className: "leap",
          },
          {
            id: 4,
            label: "编辑",
            className: "leap",
          },
          {
            id: 5,
            label: "审核",
            className: "leap",
          },
        ],
      },
    ],
  },
];

// 左边框组件方法
const handleNodeClick = (data) => {
  console.log(data.label);
  if (data.label == "测试管理员") {
    show1.value = true;
  } else {
    show1.value = false;
  }
};

const defaultProps = {
  children: "children",
  label: "label",
};
// 右边框组件方法
const customNodeClass = (data2, node) => {
  if (data2.isPenultimate) {
    return "is-penultimate";
  }
  return null;
};
</script>
<style scoped lang="scss">
.authority {
  width: 100vw;
  height: 100vh;
  background-color: #eeeeee;
  display: flex;
  justify-content: space-between;
  .left {
    width: 15%;
    height: 100vh;
    margin: 10px 5px 10px 10px;
    background-color: white;
    .title1 {
      height: 50px;
      background-color: #f6faff;
      padding: 0 10px;
      display: flex;
      align-items: center;
      h4 {
        display: flex;
        align-items: center;
      }
    }
  }
  .right {
    flex: 1;
    height: 100vh;
    margin: 10px 5px 10px 10px;
    background-color: white;
    .title2 {
      height: 50px;
      background-color: #f6faff;
      padding: 0 10px;
      display: flex;
      align-items: center;
    }
  }
}

.leap {
  display: inline-flex !important;
}

::v-deep.tree .el-tree-node__content {
  float: left;
  width: 130px;
}


</style>
